##
##	mercurial-analyzer
##	
## 	Requires: Cloc (sudo apt-get install cloc)

import analyzelib 
import settingsreader
from database import DbHandler
import logger

def getType(types, name):
	try:
		ret = types[name];
		return ret
	except Exception:
		logger.printerror("Missing type "+name)
		exit();

logger.printinfo("\t------------------------")
logger.printinfo("\t      0x90-analyzer	    ")
logger.printinfo("\t------------------------")

# Connect to mysql-db with settings from settings.xml
dbsettings = settingsreader.getdbsettings()

db = DbHandler(dbsettings)

types = settingsreader.gettypes()

# Find and analyze projects from settings.xml
projects = settingsreader.getprojects()
for project in projects:
	type = getType(types, project.type);
	analyzelib.analyze_project(project, type, db)

logger.printinfo("Done.")
